package deng.qiya.model;

import java.util.Date;
import java.util.Random;

public class CheckCode {

/**
 * SELECT [ID]      ,[PHONE]      ,[CODE]      ,[EXPIRED_TIME]      ,[SYSTEM_TIME]  FROM [CHECK_CODE]
 */
	private int id;
	private String phone;
	private String code;
	private Date ExpiredTime;
	private Date SystemTime;
	
	public CheckCode(){};
	
	public CheckCode(String code,String phone){
		this.phone = phone;
		this.code = code;
		this.ExpiredTime = new Date();
		this.SystemTime = new Date();
	}
	
	
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public Date getExpiredTime() {
		return ExpiredTime;
	}
	public void setExpiredTime(Date expiredTime) {
		ExpiredTime = expiredTime;
	}
	public Date getSystemTime() {
		return SystemTime;
	}
	public void setSystemTime(Date systemTime) {
		SystemTime = systemTime;
	}
	@Override
	public String toString() {
		return "CheckCode [id=" + id + ", phone=" + phone + ", code=" + code
				+ ", ExpiredTime=" + ExpiredTime + ", SystemTime=" + SystemTime
				+ "]";
	}
	
	public static String getRandomCode(){
		StringBuffer strBuf = new StringBuffer();
		 Random randomGenerator = new Random();
		    for (int idx = 1; idx <= 4; ++idx){
		      int randomInt = randomGenerator.nextInt(10);
		      strBuf.append(randomInt);
		    }
		    return strBuf.toString();
	}
	
}